/*
 * test.cpp
 *
 *  Created on: 2010-3-8
 *      Author: lovivid
 */

#include <cstdio>
#include <iostream>
#include "matrix.h"
#include "dengebenjin.h"
using namespace std;

int matrixtest()
{
	double val[100];
	for (int i = 0; i < 100; ++i)
	{
		val[i] = double(i);
		//cout << i << " hello world" << endl;
	}
	val[0] = 3;		val[1] = 13;	val[2] = 15;	val[3] = 1;
	val[4] = 2;		val[5] = 6;		val[6] = 3;		val[7] = 8;
	val[8] = 9;		val[9] =6 ;		val[10] = 9;	val[11] = 17;
	val[12] = 9;	val[13] = 5;	val[14] = 16;	val[16] = 12;

	jieningSquareMatrix smtxA(5, val);
	smtxA.doPrint();
	double detv = smtxA.doDetComput();
	cout << "using doDetComput, det value of the matrix = " << detv << endl;
	detv = smtxA.doDetComputR();
	cout << "using doDetComputR, det value of the matrix = " << detv << endl;

	jieningMatrix mtxZ(5,3,val);
	//mtxZ.doPrint();
	cout<<mtxZ;
	jieningMatrix tmpfcz = mtxZ.computeFCZ();
	//tmpfcz.doPrint();
	cout<<tmpfcz;
	return 0;

	jieningMatrix mtxA(10, 10, val);
	mtxA.doPrint();
	jieningMatrix mtxB(10,10, val);
	mtxB.doPrint();

	jieningMatrix mtxC = mtxA*mtxB;
	mtxC.doPrint();
	mtxC = mtxA.getSubMatrix(5, 8);
	mtxC.doPrint();
	//return 0;

	mtxA += 2.5;
	mtxA.doPrint();
	mtxA = mtxA + 2.5;
	mtxA.doPrint();
	mtxA *= 2.5;
	mtxA.doPrint();
	mtxA = mtxA * 2.5;
	mtxA.doPrint();
	mtxA -= 2.5;
	mtxA.doPrint();
	mtxA = mtxA -2.5;
	mtxA.doPrint();

	mtxC = mtxA*mtxB;
	mtxC.doPrint();

	mtxC*=mtxB;
	mtxC.doPrint();

	return 0;
}

int deng_e_ben_xi_test()
{	
	//还款月
	int tmonth = 300;
	//本金
	double total = 480000.0;
	//月利息
	double monrate = 0.042/12;
	while(true)
	{
		break;
		deng_e_ben_xi(tmonth, total, monrate);
		monrate += (0.006/12.0);
		if(monrate > (0.006/12.0)*30)
		{
			break;
		}
		break;
	}

	total = 477384;				//2010-03-20 借款总额
	monrate = 0.7*0.0594/12.0;	//2010-03-29 利率为5.94，有7折优惠, 每月按揭总额 2555
	unsigned int sumtopn=9;

	total -= 8281.68;			//2011-01-20 调息的时候已经还了9期，这9期归还的本金大概有 8281.68
	tmonth -= 9;				//已经还了9期
	monrate = 0.7*0.064/12.0;	//2011-01 开始执行利率为6.40，有7折优惠, 每月按揭总额 2633
	sumtopn = 12;

	total -= 10958;				//2012-01 调息的时候已经还了9+12期，最近12期归还的本金大概有 10958.7
	tmonth -= 12;				//又还了12期
	monrate = 0.7*0.0705/12;	//2012-01 利率调高到7.05，7折优惠情况下,每月还 2763.5,12 个月内归还本金10794.6
	sumtopn = 12;
	
	//*
	total -= 10794;				//2013-01 调息的时候已经还了9+12+12期，最近12期归还的本金大概有 10794
	tmonth -= 12;				//又还了12期
	monrate = 0.7*0.0655/12;		//2013-01 利率调低到6.55，7折优惠情况下,每月还 2675.9, 12 个月内归还本金 11846.4
	sumtopn = 12;				
	//*/

	total -= 11846;				//2014-01 调息的时候已经还了9+12+12+12期，最近12期归还的本金大概有 11846
	tmonth -= 12;				//又还了12期
	monrate = 0.7*0.0655/12;	//2014-01 利率6.55，7折优惠情况下,每月还 2675.9, 12 个月内归还本金 12401

	total -= 12401;				//2015-01 调息的时候已经还了9+12+12+12+12期，最近12期归还的本金大概有 12401, 剩余本金 423,103
	tmonth -= 12;				//又还了12期
	monrate = 0.7*0.0615/12;	//2014-01 利率6.15，7折优惠情况下,每月还 2612, 12 个月内归还本金 13391

	deng_e_ben_xi_matrix(tmonth, total, monrate, sumtopn);
	return 0;
}

#include <sys/time.h>

int main()
{
	//matrixtest();

	if(false)
	{
		timeval clkBegin;
		timeval clkEnd;
		for(int j=0;j<10;++j)
		{
			printf("loop=%d\n",j);
			gettimeofday(&clkBegin, NULL);
			int tmp=0;
			for(int i=0;i<100000000;++i)
			{
				tmp += 1;
			}
			gettimeofday(&clkEnd, NULL);

			long timecostusec = (clkEnd.tv_usec - clkBegin.tv_usec);
			timecostusec += 1000000L*(clkEnd.tv_sec - clkBegin.tv_sec);

			long timecostMs = timecostusec/1000L;
			printf("  timecostMs=%ld us=%ld\n", timecostMs, timecostusec);
		}
		return 0;
	}
	deng_e_ben_xi_test();

	return 0;
}
